# include <bits/stdc++.h>
# define mod 998244353
using namespace std;
int main()
{
    freopen("clown.in","r",stdin);
    freopen("clown.out","w",stdout);
    long long n=1;
    int m;
    cin>>m;
    while(m--)
    {
        long long x;
        cin>>x;
        n*=x;
    }
    long long a,b;
    cin>>a>>b;
    if(n==3)
    {
        cout<<(a*a%mod*a%mod*b%mod*b%mod*b%mod-a*a%mod*b%mod*b%mod*3%mod+mod+a*b%mod*2%mod)%mod<<endl;
    }
    return 0;
}